package com.xish.api.activity.update;

import com.xish.api.session.Session;
import com.xish.spring.aspect.session.CheckSession;
import com.xish.util.MediaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
public class ActivityUpdateController {

    private static final Logger LOG = LoggerFactory.getLogger(ActivityUpdateController.class);

    @CheckSession
    @RequestMapping(value = "/activity/{id}", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON,
            consumes = MediaType.APPLICATION_JSON)
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void update(@PathVariable int id,
                       @RequestBody ActivityUpdateData data,
                       @RequestHeader(value = "top_session", required = false) String sessionId,
                       Session session) {
        /**
         * 如果要验证登录信息
         * 1.方法上打CheckSession的annotation
         * 2.方法中必须要有名称为sessionId, 类型为String的参数
         * 3.如果方法中如果有名称为session, 类型为Session的参数, AOP会进行赋值, 没有则忽略
         */
        LOG.info("activity id: {}, update data: [name={}, title={}, titleVice={}]",
                id, data.getName(), data.getTitle(), data.getTitleVice());

        LOG.info("session: id={}, name={}", sessionId, session.getName());
    }

}
